//
//  HJCategroyCell.m
//  Sneakers
//
//  Created by 胡光健 on 2017/9/21.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJCategroyCell.h"
#import "HJCategpryModel.h"

@implementation HJCategroyCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.recordLabel.font = HJFontSize(mScreenWidth/414*15);
    self.sell.font = HJFontSize(mScreenWidth/414*15);
    self.buyLabel.font = HJFontSize(mScreenWidth/414*15);
    self.titleLabel.font = HJFontSize(mScreenWidth/414*15);
    self.sellLabel.font = HJFontSize(mScreenWidth/414*13);
    self.goodNoLabel.font = HJFontSize(mScreenWidth/414*13);
    self.moneyLabel.font = HJFontSize(mScreenWidth/414*19);
    self.percentLabel.font = HJFontSize(mScreenWidth/414*15);
    self.collectBtn.titleLabel.font = HJFontSize(mScreenWidth/414 *13);
    self.selecte = NO;
}

-(void)setModel:(HJCategpryModel *)model {
    _model = model;
    
    [self.mainImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",model.avatar_base_url,model.avatar_path]]];
    self.titleLabel.text =model.shoes_name;

    self.moneyLabel.text =[NSString stringWithFormat:@"￥%@",model.reference_price];
    self.sellLabel.text =[NSString stringWithFormat:@"发售价：￥%@",model.sell_money];
    self.goodNoLabel.text = [NSString stringWithFormat:@"货号 %@",model.shoes_article_number];
    self.buyLabel.text = [NSString stringWithFormat:@"求购 %@ ",model.want_buy_num];
    self.sell.text = [NSString stringWithFormat:@"出售 %@ ",model.sell_num];
    self.recordLabel.text = [NSString stringWithFormat:@"交易记录 %@ ",model.sales];
    if ([model.state2 isEqual:@0]) {
        self.percentLabel.textColor = HJColor(255, 72, 74);
        self.imaeHide.image = HJImage(@"Fill 7");
    }else {
        self.percentLabel.textColor = HJColor(71, 201, 157);
        self.imaeHide.image = HJImage(@"Fill 1 Copy 00");
    }
    if ([model.percent isEqualToString:@"0.00"]) {
        self.percentLabel.text = @"";
        self.imaeHide.hidden = YES;
    }else {
        self.percentLabel.text = [NSString stringWithFormat:@"%@%%",model.percent];
    }
    if ([model.collection_status isEqual:@1]) {
        self.collectionImage.image= HJImage(@"Fill 1 Copy 8");
        self.collectionLabel.text= @"已收藏";
    }else {
        self.collectionImage.image=HJImage(@"Fill 1 star");
        self.collectionLabel.text= @"收藏";
    }
    
}
// 收藏
- (IBAction)collectBtn:(UIButton *)sender {
    if ([HJUserManager isLoginView]) {
        return;
    }
    sender.selected = !sender.selected;
    if (sender.selected) {
        _model.collection_status = @1;
        self.collectionImage.image=HJImage(@"Fill 1 Copy 8");
        self.collectionLabel.text= @"已收藏";
    }else {
        self.collectionImage.image=HJImage(@"Fill 1 star");
        self.collectionLabel.text= @"收藏";
        _model.collection_status = @0;
    }
    MJWeakSelf
    [TZHttpTool post:CollectionShoesAPI params:@{@"shoes_id":_model.shoes_id} success:^(NSDictionary *result) {
         weakSelf.collection_count++;
        [[UIViewController currentViewController] showHint:result[@"msg"]];
    } failure:^(NSString *msg) {
        weakSelf.collection_count--;
        [[UIViewController currentViewController] showHint:msg];
    }];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"collectionNotification" object:nil userInfo:@{@"i":@(self.collection_count)}];
    
    if (!self.collectBool) {
        self.collectionBtnBlock(self.collectBool);
    }
    
}

@end
